package logic;

/**
 * @author Niels
 * 
 */
public class AfterDecryption {

	String replyAuth;
	String userEmail;
	String userPass;
	String amountString;
	double transferAmount;
	String receiptDateTimeTxt;
	String receiptDateTime;
	String receiptCopyright;
	String receiptAmount;
	String type;
	String mailToUser;

	/**
	 * Handles and splits the strings in coming
	 * @param decryptedmessage
	 */
	public AfterDecryption(String decryptedmessage) {

		String[] decrypteddata_array = decryptedmessage.split(":");

		if (decrypteddata_array[0].trim().equals("AUTH")) {
			System.out
					.println("Step 5. AfterEncryption splits decrypted message into a String array: "
							+ decrypteddata_array[0].trim()
							+ " "
							+ decrypteddata_array[1].trim()
							+ " "
							+ decrypteddata_array[2].trim());

			userEmail = decrypteddata_array[1].trim();
			userPass = decrypteddata_array[2].trim();

			type = new String("AUTH");
		} else if (decrypteddata_array[0].trim().equals("TRANSFER")) {
			System.out
					.println("Step 5. AfterEncryption splits decrypted message into a String array: "
							+ decrypteddata_array[0].trim()
							+ " "
							+ decrypteddata_array[1].trim()
							+ " "
							+ decrypteddata_array[2].trim()
							+ " "
							+ decrypteddata_array[3].trim());

			userEmail = decrypteddata_array[1].trim();
			userPass = decrypteddata_array[2].trim();
			amountString = decrypteddata_array[3].trim();
			transferAmount = Double.parseDouble(amountString);

			System.out.println("TRANSFER AMOUNT: " + transferAmount);

			type = new String("TRANSFER");
		} else if (decrypteddata_array[0].trim().equals("TRANSFERTOUSER")) {
			System.out
					.println("Step 5. AfterEncryption splits decrypted message into a String array: "
							+ decrypteddata_array[0].trim()
							+ " "
							+ decrypteddata_array[1].trim()
							+ " "
							+ decrypteddata_array[2].trim()
							+ " "
							+ decrypteddata_array[3].trim()
							+ " "
							+ decrypteddata_array[4].trim());

			userEmail = decrypteddata_array[1].trim();
			userPass = decrypteddata_array[2].trim();
			mailToUser = decrypteddata_array[3].trim();
			amountString = decrypteddata_array[4].trim();
			System.out.println(amountString);
			transferAmount = Double.parseDouble(amountString);

			System.out.println("TRANSFER AMOUNT: " + transferAmount);

			type = new String("TRANSFERTOUSER");
		} else if (decrypteddata_array[0].trim().equals("RECEIPT")) {
			System.out
					.println("Step 5. AfterEncryption splits decrypted message into a String array: "
							+ decrypteddata_array[0].trim()
							+ " "
							+ decrypteddata_array[1].trim()
							+ " "
							+ decrypteddata_array[2].trim()
							+ " "
							+ decrypteddata_array[3].trim()
							+ " "
							+ decrypteddata_array[4].trim()
							+ " "
							+ decrypteddata_array[5].trim()
							+ " "
							+ decrypteddata_array[6].trim());

			userEmail = decrypteddata_array[1].trim();
			userPass = decrypteddata_array[2].trim();
			receiptDateTimeTxt = decrypteddata_array[3].trim();
			receiptDateTime = decrypteddata_array[4].trim();
			receiptCopyright = decrypteddata_array[5].trim();
			receiptAmount = decrypteddata_array[6].trim();

			System.out.println("THIS IS RECEIPT AMOUNT IN AFTERDECRYPT: "
					+ receiptAmount);

			type = new String("RECEIPT");

		} else {
			System.err
					.println("WARNING: INTERNAL SERVER ERROR"
							+ " - SERVER DID NOT RECEIVE AUTH OR TRANSFER"
							+ "PROTOCOL");
		}
	}

	public String getAmountString() {
		return amountString;
	}

	public void setAmountString(String amountString) {
		this.amountString = amountString;
	}

	public String getMailToUser() {
		return mailToUser;
	}

	public void setMailToUser(String mailToUser) {
		this.mailToUser = mailToUser;
	}

	public void setTransferAmount(double transferAmount) {
		this.transferAmount = transferAmount;
	}

	public String getReceiptAmount() {
		return receiptAmount;
	}

	public String getReceiptDateTimeTxt() {
		return receiptDateTimeTxt;
	}

	public void setReceiptDateTimeTxt(String receiptDateTimeTxt) {
		this.receiptDateTimeTxt = receiptDateTimeTxt;
	}

	public String getReceiptDateTime() {
		return receiptDateTime;
	}

	public void setReceiptDateTime(String receiptDateTime) {
		this.receiptDateTime = receiptDateTime;
	}

	public String getReceiptCopyright() {
		return receiptCopyright;
	}

	public void setReceiptCopyright(String receiptCopyright) {
		this.receiptCopyright = receiptCopyright;
	}

	public String getUserEmail() {
		return userEmail;
	}

	public String getUserPass() {
		return userPass;
	}

	public Double getTransferAmount() {
		return transferAmount;
	}

	public String getType() {
		return type;
	}

}
